package com.yamanyar.weebill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.yamanyar.weebill.domain.Project;
import com.yamanyar.weebill.service.ProjectService;

/**
 * Creates a Project. Created in Jun 28, 2008.
 * 
 * @author Kaan Yamanyar
 */
@org.springframework.stereotype.Component("createProject")
@Scope("request")
public class CreateProject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6785907946599065081L;

	private ProjectService projectService;

	private Project project = new Project();

	@Autowired
	public CreateProject(ProjectService projectService) {
		this.projectService = projectService;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public String save() {
		projectService.createNew(project);
		FacesMessage facesMessage = new FacesMessage(
				FacesMessage.SEVERITY_INFO, "Project is saved successfully",
				"OK");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		project = new Project();
		return null;
	}
}
